// HookManager.cpp: implementation of the CHookManager class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GameStart.h"
#include "HookManager.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
CHookManager* CHookManager::m_pInstance=NULL;
CHookManager::CHookManager()
{
	m_hModule=NULL;
	m_bIsRunning=FALSE;
	m_pSetAcc=NULL;
	m_pSetHook=NULL;
}

CHookManager::~CHookManager()
{
	m_hModule=NULL;
	if(m_pInstance!=NULL)
	{
		delete m_pInstance;
		m_pInstance=NULL;
	}
}

CHookManager* CHookManager::CreateInstance()
{
	if(m_pInstance==NULL)
	{
		m_pInstance=new CHookManager(); 
		m_pInstance->m_hModule=LoadLibrary(_T("myhook.dll"));
		m_pInstance->m_pSetHook=(lpFuncSetHook)GetProcAddress(m_pInstance->m_hModule,(LPCSTR)"SetHook");
		m_pInstance->m_pSetAcc=(lpFuncSetAcc)GetProcAddress(m_pInstance->m_hModule,(LPCSTR)"SetAcc");
		if(!m_pInstance->m_pSetHook)
		{
			m_pInstance->m_bIsRunning=FALSE; return NULL;
		}
		if(!m_pInstance->m_pSetAcc)
		{
			m_pInstance->m_bIsRunning=FALSE; return NULL;
		}
	}
	return m_pInstance;
}

void CHookManager::SetAccount(int iAccIndex)
{
	if(m_pSetAcc!=NULL)
	{ 
		m_pSetAcc(iAccIndex);
	}
}

void CHookManager::SetHookFunc()
{
	if(m_pSetHook!=NULL)
	{
		m_pSetHook();
	}
}